<template>
  <div>
    <div class="topDiv" ><span style="font-size: 32px;">{{zrsMbInfo.mbName}}</span>模版设计
        <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleUpdateKhDeptSel(zrsMbInfo)"
            v-if="!isDisabled && zrsMbInfo.mbType == '1'"
            v-hasPermi="['business:ZrsMbManageGoal:edit']"
          >添加被考核部门</el-button>
        <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleUpdateKhUserSel(zrsMbInfo)"
            v-if="!isDisabled && zrsMbInfo.mbType == '2'"
            v-hasPermi="['business:ZrsMbManageGoal:edit']"
          >添加被考核人员</el-button>
    </div>
    <div class="talbeDiv">
      <div v-for="zrsMbManageGoal in ZrsMbManageGoalList" >
        <span>{{zrsMbManageGoal.goalName}}</span>
        <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(zrsMbManageGoal)"
            v-if="!isDisabled"
            v-hasPermi="['business:ZrsMbManageGoal:edit']"
          >修改</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-circle-check"
              @click="handleSelZb(zrsMbManageGoal)"
              v-if="!isDisabled"
              v-hasPermi="['business:ZrsMbManageGoal:edit']"
            >选择指标</el-button>

            <el-button
                size="mini"
                type="text"
                icon="el-icon-circle-check"
                @click="handleAddYjZb(zrsMbManageGoal)"
                v-if="!isDisabled"
                v-hasPermi="['business:ZrsMbManageGoal:edit']"
              >添加指标</el-button>

        <div style="padding-top: 10px;" v-if="glxZbData['glx_zblist_'+zrsMbManageGoal.mbGoalId]">
          <table class="talbeClass table-striped table-bordered table-hover" :id="'talbe_'+zrsMbManageGoal.mbGoalId" :name="'talbe_'+zrsMbManageGoal.mbGoalId">
            <thead>
            <tr style="font-size:20px;background-color: rgb(223, 223, 223);">
              <th style="width: 15%;">指标名称</th>
              <th style="width: 35%;" colspan="2">基本要求</th>
              <th style="width: 10%;">分值（分）</th>
              <th style="width: 15%;">质量标准</th>
              <th style="width: 10%;">考核周期</th>
              <th style="width: 15%;">考核部门</th>
            </tr>
            </thead>
            <tbody>
              <template  v-for="(zrsGoalZbMap , index) in glxZbData['glx_zblist_'+zrsMbManageGoal.mbGoalId]">
                <template v-for="(ejzbMap , i ) in zrsGoalZbMap.erzbList">
                  <template v-if="ejzbMap.sjzbList.length ==0"> <!-- 三级指标不存在的时候 -->
                    <template v-if="i==0">
                      <tr>
                        <td :rowspan="zrsGoalZbMap.yjrs">{{zrsGoalZbMap.yjzbmc}} <!--  一级指标名称  -->
                          <el-button
                              size="mini"
                              type="text"
                              icon="el-icon-edit"
                              @click="handleZbUpdate(zrsGoalZbMap.yjzbid)"
                              v-if="!isDisabled"
                              v-hasPermi="['business:ZrsMbManageGoal:edit']"
                            >修改</el-button>
                          <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit"
                                @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,zrsGoalZbMap.yjzbid,'1')"
                                v-if="!isDisabled"
                                v-hasPermi="['business:ZrsMbManageGoal:edit']"
                              >添加下级指标</el-button>
                        </td>
                        <td :rowspan="ejzbMap.errs" colspan="2" style="text-align: left;">{{ejzbMap.erzbmc}}<!--  二级指标名称  -->
                          <el-button
                              size="mini"
                              type="text"
                              icon="el-icon-edit"
                              @click="handleZbUpdate(ejzbMap.erzbid)"
                              v-if="!isDisabled && ejzbMap.erzbmc"
                              v-hasPermi="['business:ZrsMbManageGoal:edit']"
                            >修改</el-button>
                          <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit"
                                @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,ejzbMap.erzbid,'2')"
                                v-if="!isDisabled"
                                v-hasPermi="['business:ZrsMbManageGoal:edit']"
                              >添加下级指标</el-button>
                        </td>
                        <!-- 分值 -->
                        <td v-if="zrsGoalZbMap.yjIsDfZb == '0'" :rowspan="zrsGoalZbMap.yjrs-1">{{zrsGoalZbMap.yjfz}}</td>
                        <td v-else>{{ejzbMap.erfz}}</td>
                        <!-- 分值end -->
                        <td>{{ejzbMap.erbz}}</td>
                        <td>
                          <el-select v-model="ejzbMap.erKhzq" placeholder="模版指标考核周期" :disabled="isDisabled" @change="((val) => selectChange(val,ejzbMap.erzbid))">
                            <el-option
                              v-for="dict in dict.type.zrs_zb_checkdate"
                              :key="dict.value"
                              :label="dict.label"
                              :value="dict.value"
                            ></el-option>
                          </el-select>
                        </td>
                        <td :rowspan="zrsGoalZbMap.yjrs"> <!-- 考核部门设置 -->
                            <el-select v-model="zrsGoalZbMap.yjZrszbShDept" placeholder="选择考核部门" :disabled="isDisabled" filterable @change="((val) => selectChangeShDept(val,zrsGoalZbMap.yjzbid))">
                              <el-option
                                v-for="dict in shDeptInfo"
                                :key="dict.key"
                                :label="dict.label"
                                :value="dict.key"
                              ></el-option>
                            </el-select>
                        </td>
                      </tr>
                    </template>
                    <template v-else>
                      <tr>
                        <td :rowspan="ejzbMap.errs" colspan="2" style="text-align: left;">{{ejzbMap.erzbmc}} <!--  二级指标名称  -->
                          <el-button
                              size="mini"
                              type="text"
                              icon="el-icon-edit"
                              @click="handleZbUpdate(ejzbMap.erzbid)"
                              v-if="!isDisabled"
                              v-hasPermi="['business:ZrsMbManageGoal:edit']"
                            >修改</el-button>
                          <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit"
                                @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,ejzbMap.erzbid,'2')"
                                v-if="!isDisabled"
                                v-hasPermi="['business:ZrsMbManageGoal:edit']"
                              >添加下级指标</el-button>
                        </td>
                        <td v-if="zrsGoalZbMap.yjIsDfZb != '0'">{{ejzbMap.erfz}}</td>
                        <td>{{ejzbMap.erbz}}</td>
                        <td>
                          <el-select v-model="ejzbMap.erKhzq" placeholder="模版指标考核周期" :disabled="isDisabled" @change="((val) => selectChange(val,ejzbMap.erzbid))">
                            <el-option
                              v-for="dict in dict.type.zrs_zb_checkdate"
                              :key="dict.value"
                              :label="dict.label"
                              :value="dict.value"
                            ></el-option>
                          </el-select>
                        </td>
                      </tr>
                    </template>
                  </template>
                <template v-else>
                  <template v-for="(sjzbMap , j ) in ejzbMap.sjzbList">  <!-- 判断三级指标是存在 -->

                      <template v-if="i == 0 && j==0 ">
                          <tr>
                            <td :rowspan="zrsGoalZbMap.yjrs">{{zrsGoalZbMap.yjzbmc}}
                              <el-button
                                  size="mini"
                                  type="text"
                                  icon="el-icon-edit"
                                  @click="handleZbUpdate(zrsGoalZbMap.yjzbid)"
                                  v-if="!isDisabled"
                                  v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                >修改</el-button>
                              <el-button
                                    size="mini"
                                    type="text"
                                    icon="el-icon-edit"
                                    @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,zrsGoalZbMap.yjzbid,'1')"
                                    v-if="!isDisabled"
                                    v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                  >添加下级指标</el-button>
                            </td>
                            <td :rowspan="ejzbMap.errs" style="text-align: left; width: 13%;" >{{ejzbMap.erzbmc}}
                              <el-button
                                  size="mini"
                                  type="text"
                                  icon="el-icon-edit"
                                  @click="handleZbUpdate(ejzbMap.erzbid)"
                                  v-if="!isDisabled"
                                  v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                >修改</el-button>
                              <el-button
                                    size="mini"
                                    type="text"
                                    icon="el-icon-edit"
                                    @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,ejzbMap.erzbid,'2')"
                                    v-if="!isDisabled"
                                    v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                  >添加下级指标</el-button>
                            </td>
                            <td style="text-align: left;">{{sjzbMap.sjzbmc}}</td>
                            <td v-if="ejzbMap.erIsDfZb == '0'" :rowspan="ejzbMap.errs">{{ejzbMap.erfz}}</td>
                            <td v-else>{{sjzbMap.sjfz}}</td>
                            <td>{{sjzbMap.sjbz}}</td>
                            <td>
                              <el-select v-model="sjzbMap.sjKhzq" placeholder="模版指标考核周期" :disabled="isDisabled" @change="((val) => selectChange(val,ejzbMap.erzbid))">
                                <el-option
                                  v-for="dict in dict.type.zrs_zb_checkdate"
                                  :key="dict.value"
                                  :label="dict.label"
                                  :value="dict.value"
                                ></el-option>
                              </el-select>
                            </td>
                            <td :rowspan="zrsGoalZbMap.yjrs"> <!-- 考核部门设置 -->
                                <el-select v-model="zrsGoalZbMap.yjZrszbShDept" placeholder="选择考核部门" :disabled="isDisabled" filterable @change="((val) => selectChangeShDept(val,zrsGoalZbMap.yjzbid))">
                                  <el-option
                                    v-for="dict in shDeptInfo"
                                    :key="dict.key"
                                    :label="dict.label"
                                    :value="dict.key"
                                  ></el-option>
                                </el-select>
                            </td>
                          </tr>
                        </template>
                        <template v-else-if="j==0">
                          <tr>
                            <td :rowspan="ejzbMap.errs" style="text-align: left;width: 13%;">{{ejzbMap.erzbmc}}<!--  二级指标名称  -->
                              <el-button
                                  size="mini"
                                  type="text"
                                  icon="el-icon-edit"
                                  @click="handleZbUpdate(ejzbMap.erzbid)"
                                  v-if="!isDisabled"
                                  v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                >修改</el-button>
                              <el-button
                                      size="mini"
                                      type="text"
                                      icon="el-icon-edit"
                                      @click="handleAddChildZb(zrsMbManageGoal.mbGoalId,ejzbMap.erzbid,'2')"
                                      v-if="!isDisabled"
                                      v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                    >添加下级指标</el-button>
                            </td>
                            <td style="text-align: left;">{{sjzbMap.sjzbmc}}<!--  三级指标名称  -->
                              <el-button
                                  size="mini"
                                  type="text"
                                  icon="el-icon-edit"
                                  @click="handleZbUpdate(sjzbMap.sjzbid)"
                                  v-if="!isDisabled"
                                  v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                >修改</el-button>
                            </td>
                            <td v-if="ejzbMap.erIsDfZb == '0'" :rowspan="ejzbMap.errs">{{ejzbMap.erfz}}</td>
                            <td v-else>{{sjzbMap.sjfz}}</td>
                            <td style="white-space: pre-wrap;">{{sjzbMap.sjbz}}</td>
                            <td>
                              <el-select v-model="sjzbMap.sjKhzq" placeholder="模版指标考核周期"  :disabled="isDisabled" @change="((val) => selectChange(val,sjzbMap.sjzbid))">
                                <el-option
                                  v-for="dict in dict.type.zrs_zb_checkdate"
                                  :key="dict.value"
                                  :label="dict.label"
                                  :value="dict.value"
                                ></el-option>
                              </el-select>
                            </td>
                          </tr>
                        </template>
                        <template v-else>
                          <tr>
                            <td style="text-align: left;">{{sjzbMap.sjzbmc}}
                              <el-button
                                  size="mini"
                                  type="text"
                                  icon="el-icon-edit"
                                  @click="handleZbUpdate(sjzbMap.sjzbid)"
                                  v-if="!isDisabled"
                                  v-hasPermi="['business:ZrsMbManageGoal:edit']"
                                >修改</el-button>
                            </td>
                            <td v-if="ejzbMap.erIsDfZb == '1'">{{sjzbMap.sjfz}}</td>
                            <td style="white-space: pre-wrap;">{{sjzbMap.sjbz}}</td>
                            <td>
                              <el-select v-model="sjzbMap.sjKhzq" placeholder="模版指标考核周期" :disabled="isDisabled" @change="((val) => selectChange(val,sjzbMap.sjzbid))">
                                <el-option
                                  v-for="dict in dict.type.zrs_zb_checkdate"
                                  :key="dict.value"
                                  :label="dict.label"
                                  :value="dict.value"
                                ></el-option>
                              </el-select>
                            </td>
                          </tr>
                        </template>
                        <template v-if="(j+1) == ejzbMap.sjzbList.length && ejzbMap.erbz ">
                          <tr><td :colspan="4">{{ejzbMap.erbz}}</td></tr>
                        </template>
                      </template>
                  </template>
                </template>
                <!-- 一级指标的备注部分 -->
                <template v-if="zrsGoalZbMap.yjbz">
                  <tr>
                    <td colspan="5">{{zrsGoalZbMap.yjbz}}</td>
                 </tr>
                </template>
              </template>
            </tbody>
          </table>
        </div>
        <div style="padding-top: 8px;padding-bottom:6px;font-size: 16px;font-weight:bold;text-indent: 4ch;">{{zrsMbManageGoal.remark}}</div>
      </div>
    </div>
    <div style="padding-top: 37px;padding-left: 30%;" v-if="!isDisabled">
      <div class="demo-shadow" style="box-shadow: rgb(0 0 0 / 12%) 0px 2px 4px, rgb(0 0 0 / 4%) 0px 0px 6px;" @click="handleAdd">
        +<br/>
        添加管理目标项
      </div>
    </div>

    <!-- 添加或修改目标项管理记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="目标名称" prop="goalName">
          <el-input v-model="form.goalName" placeholder="请输入目标名称" />
        </el-form-item>
        <el-form-item label="目标简称" prop="goalJname">
          <el-input v-model="form.goalJname" placeholder="请输入目标简称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" rows="5" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="说明" prop="introduction">
          <el-input v-model="form.introduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择指标 -->
    <el-dialog :title="title" :visible.sync="selZbOpen" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <div class="edit_dev">
        <el-transfer v-model="selGlxZbVal" :data="zbData" :titles="['未选指标', '已选指标']" filterable  :filter-method="filterMethod"></el-transfer>
      </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormGlxZb">确 定</el-button>
        <el-button @click="cancelSelZb">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择指标 END-->
    <!-- 选择被考核部门 -->
    <el-dialog :title="title" :visible.sync="selKhDeptOpen" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <div class="edit_dev">
        <!--<el-transfer v-model="selKhDeptVal" :data="khDept" :titles="['未选部门', '已选被考核部门']" filterable  :filter-method="filterMethod"></el-transfer>-->
        <el-transfer
            filterable
            :filter-method="filterMethod"
            filter-placeholder="请输入查询条件"
            :titles="['未选部门', '已选被考核部门']"
            :button-texts="['移除', '添加']"
            v-model="selKhDeptVal"
            :data="khDept">
        </el-transfer>
      </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormZbKhDept">确 定</el-button>
        <el-button @click="cancelSelKhDept">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择被考核部门 END-->
    <!-- 选择被考核人员 -->
    <el-dialog :title="title" :visible.sync="selKhUserOpen" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <div class="edit_dev">
        <el-transfer
            filterable
            :filter-method="filterMethod"
            filter-placeholder="请输入查询条件"
            :titles="['未选人员', '已选被考核人员']"
            :button-texts="['移除', '添加']"
            v-model="selKhUserVal"
            :data="khUser">
        </el-transfer>
      </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormZbKhUser">确 定</el-button>
        <el-button @click="cancelSelKhUser">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择被考核人员 END-->
    <!-- 添加或修改指标管理对话框 -->
    <el-dialog :title="title" :visible.sync="openZb" width="720px" append-to-body>
      <el-form ref="zbform" :model="zbform" :rules="zbrules" label-width="120px">
        <!--
        <el-form-item label="父部门id" prop="parentId">
          <treeselect v-model="form.parentId" :options="zbmanageOptions" :normalizer="normalizer" placeholder="请选择父部门id" />
        </el-form-item> -->
        <el-form-item label="指标名称" prop="zbName">
          <el-input v-model="zbform.zbName" placeholder="请输入指标名称" />
        </el-form-item>
        <el-form-item label="指标简称" prop="zbJname">
          <el-input v-model="zbform.zbJname" placeholder="请输入指标简称" />
        </el-form-item>
        <!--
        <el-form-item label="指标层级" prop="zbLevel">
          <el-radio-group v-model="form.zbLevel">
            <el-radio
              v-for="dict in dict.type.sys_zb_level"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-row>
          <el-col :span="12" v-if="zbform.zbLevel != '3'">
            <el-form-item label="一票否决指标" prop="isVeto" >
              <el-radio-group v-model="zbform.isVeto">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no_num"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="zbform.zbLevel == '1'">
            <el-form-item label="增补指标" prop="isBonusZb">
              <el-radio-group v-model="zbform.isBonusZb">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no_num"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="是否打分指标" prop="isDfZb">
              <el-radio-group v-model="zbform.isDfZb">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no_num"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!--
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_status"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="指标分数" prop="zbFz">
              <el-input-number v-model="zbform.zbFz" placeholder="请输入指标分数" :step="0.01" :max="100" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示顺序" prop="orderNum">
              <el-input-number v-model="zbform.orderNum" placeholder="请输入显示顺序" :max="9999"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="zbform.remark" type="textarea" rows="5" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="说明" prop="introduction">
          <el-input v-model="zbform.introduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-row v-if="zbform.zbId">
          <el-col :span="12" >
            <el-form-item label="是否同步更新指标库" prop="isSynZb" label-width="150px">
              <el-radio-group v-model="zbform.isSynZb">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no_num"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitMbZbForm">确 定</el-button>
        <el-button @click="cancelZb">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加和修改指标对话框  end -->
  </div>
</template>

<script>
import { listZrsMbManageGoal,listZrsMbManageGoalZb, getZrsMbManageGoal,
  delZrsMbManageGoal, addZrsMbManageGoal, updateZrsMbManageGoal,
  getZrsMbManageGoalSelZb,updateZrsMbManageGoalToSaveZb,
  getZrsMbManageKhDeptSel,updateZrsMbManageShDeptToSaveDept,
  getZrsMbManageKhUserSel,updateZrsMbManageShUserToSaveUser,
  updateZrsMbGlxZb,getMbZbmanage,updateMbZbmanage,addMbZbmanage
  } from "@/api/business/ZrsMbManageGoal";

export default {
  name: "ZrsMbManageGoal",
  dicts: ['zrs_zb_checkdate','sys_yes_no_num'],
  data() {
    return {
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      // 遮罩层
      loading: true,
      isDisabled:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 目标项管理记录表格数据
      ZrsMbManageGoalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        mbId: null,
        goalName: null,
        goalJname: null,
        status: null,
        introduction: null,
        delTime: null,
        delBy: null
      },
      // 表单参数
      form: {},
      zbform:{},
      // 表单校验
      rules: {
        goalName: [
          { required: true, message: "目标名称不能为空", trigger: "blur" }
        ],
        goalJname: [
          { required: true, message: "目标简称不能为空", trigger: "blur" }
        ],
      },
      // 表单校验
      zbrules: {
        zbName: [
          { required: true, message: "指标名称不能为空", trigger: "blur" }
        ],
        zbJname: [
          { required: true, message: "指标简称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "排序不能为空", trigger: "blur" }
        ],
      },
      mbId:null,//模版名称
      selZbOpen:false, //选择指标 弹框
      selGlxZbVal:[] ,//已选的管理项指标模版
      zbData:[],//没有选择的指标列表
      glxZbData:null,//管理项数据对象
      zrsMbInfo:{"mbName":''},//模版对象

      selKhDeptOpen:false,//选择考核部门 弹出
      selKhDeptVal:[],  //选择的考核
      khDept:[],

      selKhUserOpen:false,//选择考核部门 弹出
      selKhUserVal:[],  //选择的考核
      khUser:[],


      shDeptInfo:[],//打分部门

      openZb:false,


    };
  },
  created() {
    const mbId = this.$route.params && this.$route.params.mbId;
    //console.log(tableId);
    if(mbId){
      this.mbId = mbId;
      this.queryParams.mbId = this.mbId;
      //处理业务
      this.getList();
    }else{
      this.close();
      return ;
    }
  },
  methods: {
    /** 关闭按钮 */
    close() {
      const obj = { path: "/zhib/ZrsMbManage", query: { t: Date.now(), pageNum: this.$route.query.pageNum } };
      this.$tab.closeOpenPage(obj);
    },
    /** 查询目标项管理记录列表 */
    getList() {
      let that = this;
      that.loading = true;
      listZrsMbManageGoalZb(that.queryParams).then(response => {
        that.glxZbData = response.data;  //返回的所有数据
        that.ZrsMbManageGoalList = response.data.mbGlxList; //只有管理项数据list
        that.zrsMbInfo = response.data.zrsMbInfo;//查询模版数据
        that.shDeptInfo = response.data.shDeptInfo;
        that.isDisabled = (that.zrsMbInfo.isEnable ==='1');
        that.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelSelZb() {
      this.selZbOpen = false;
      this.zbData = null;
      this.selGlxZbVal = [] ;//已选的管理项指标模版
      this.title = "";
    },
    cancelSelKhDept() {
      this.selKhDeptOpen = false;
      this.khDept = null;
      this.selKhDeptVal = [] ;//已选的管理项指标模版
      this.title = "";
    },
    cancelSelKhUser() {
      this.selKhUserOpen = false;
      this.khUser = null;
      this.selKhUserVal = [] ;//已选的管理项指标模版
      this.title = "";
    },
    // 取消按钮
    cancelZb() {
      this.openZb = false;
      this.mbZbReset();
    },
    // 表单重置
    reset() {
      this.form = {
        mbGoalId: null,
        mbId: null,
        goalName: null,
        goalJname: null,
        status: null,
        delFlag: null,
        remark: null,
        introduction: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delTime: null,
        delBy: null
      };
      this.resetForm("form");
    },
    mbZbReset() {
      this.zbform = {
        zrszbId:null,
        mbGoalId: null,
        mbId: null,
        zbId: null,
        parentId: null,
        ancestors: null,
        zbName: null,
        zbJname: null,
        zbLevel: null,
        isDfZb:'1',
        zbFz: null,
        orderNum: null,
        remark: null,
        introduction: null,
        isVeto: '1',
        isBonusZb: '1',
      };
      this.resetForm("zbform");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSelZb(row){ //弹框选择  指标
      //弹框选择
      this.reset();
      const mbGoalId = row.mbGoalId || this.ids
      let mbId = this.mbId;
      let param = {
        mbId:mbId,  //模版id
        mbGoalId: mbGoalId,//管理项id
      }
      getZrsMbManageGoalSelZb(param).then(response => {
        this.zbData = response.data.zbData;
        this.selGlxZbVal = response.data.selGlxZbVal == null ? []: response.data.selGlxZbVal;//已选的管理项指标模版
        this.selZbOpen = true;
        this.title = "选择指标";
        this.form.mbId = mbId;
        this.form.mbGoalId = mbGoalId;
      });
    },
    submitFormGlxZb(){
      this.form.selGlxZbVal = this.selGlxZbVal;
      updateZrsMbManageGoalToSaveZb(this.form).then(response => {
        this.$modal.msgSuccess("指标已选择！");
        this.selZbOpen = false;
        this.cancelSelZb();
        this.getList();
      });
    },
    handleUpdateKhDeptSel(row){ //弹框选择  指标
      //弹框选择
      this.reset();
      let mbId = this.mbId;
      let param = {
        mbId:mbId  //模版id
      }
      getZrsMbManageKhDeptSel(param).then(response => {
        this.khDept = response.data.khDept;
        this.selKhDeptVal = response.data.selKhDeptVal == null ? []: response.data.selKhDeptVal;//已选的管理项指标模版
        this.selKhDeptOpen = true;
        this.title = "选择被考核部门";
        this.form.mbId = mbId;
      });
    },
    handleUpdateKhUserSel(row){ //弹框选择  指标
      //弹框选择
      this.reset();
      let mbId = this.mbId;
      let param = {
        mbId:mbId  //模版id
      }
      getZrsMbManageKhUserSel(param).then(response => {
        this.khUser = response.data.khUser;
        this.selKhUserVal = response.data.selKhUserVal == null ? []: response.data.selKhUserVal;//已选的管理项指标模版
        this.selKhUserOpen = true;
        this.title = "选择被考核人员";
        this.form.mbId = mbId;
      });
    },
    submitFormZbKhUser(){
      console.log(this.selKhUserVal);
      console.log(!this.selKhUserVal);
      if(this.selKhUserVal.length == 0){
        this.$modal.msgSuccess("没有选择考核人员，无需点击【确定】");
        return ;
      }
      this.form.selKhUserVal = this.selKhUserVal;
      updateZrsMbManageShUserToSaveUser(this.form).then(response => {
        this.$modal.msgSuccess("被考核人员已保存！");
        this.selKhUserOpen = false;
        this.cancelSelKhUser();
        //this.getList();
      });
    },

    submitFormZbKhDept(){
      if(this.selKhDeptVal.length == 0){
        this.$modal.msgSuccess("没有选择考核部门，无需点击【确定】");
        return ;
      }
      this.form.selKhDeptVal = this.selKhDeptVal;
      updateZrsMbManageShDeptToSaveDept(this.form).then(response => {
        this.$modal.msgSuccess("被考核部门已保存！");
        this.selKhDeptOpen = false;
        this.cancelSelKhDept();
        //this.getList();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.mbGoalId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      if(this.mbId){
        this.reset();
        this.open = true;
        this.title = "添加目标项管理记录";
        this.form.mbId = this.mbId;
      }else{
        this.$modal.msgSuccess("参数有误，请检查参数！！");
        return ;
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const mbGoalId = row.mbGoalId || this.ids
      getZrsMbManageGoal(mbGoalId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改目标项管理记录";
      });
    },
    handleAddYjZb(row){ //手动添加 一级指标
      this.mbZbReset();
      if(!this.mbId){
        this.$alert("模版参数不能为空！");
        return ;
      }
      if(!row.mbGoalId){
        this.$alert("模版管理项不能为空！");
        return ;
      }
      this.zbform.parentId = 0;
      this.zbform.zbLevel = '1';
      this.zbform.mbGoalId = row.mbGoalId;
      this.zbform.mbId = this.mbId;
      this.openZb = true;
      this.title = "添加模版指标管理";

    },
    handleAddChildZb(mbGoalId,yjzbid,zblevel){
      this.mbZbReset();
      if(!this.mbId){
        this.$alert("模版参数不能为空！");
        return ;
      }
      if(!mbGoalId){
        this.$alert("模版管理项不能为空！");
        return ;
      }
      this.zbform.parentId = yjzbid;
      if(zblevel === '1'){
        this.zbform.zbLevel = "2";
      }else if(zblevel === '2'){
        this.zbform.zbLevel = "3";
      }
      this.zbform.mbGoalId = mbGoalId;
      this.zbform.mbId = this.mbId;
      this.openZb = true;
      this.title = "添加模版指标管理";
    },
    handleZbUpdate(zbid){
      //获取  模版指标信息  然后进行修改
      this.mbZbReset();
      //this.getTreeselect();
      /**
      if (row != null) {
        this.zbform.parentId = row.parentId;
      } **/
      if(!this.mbId){
        this.$alert("模版参数不能为空！");
        return ;
      }
      if(!zbid){
        this.$alert("模版指标参数不能为空！");
        return ;
      }
      let data = {
        mbId:this.mbId,
        zbId:zbid,
      }
      getMbZbmanage(data).then(response => {
        this.zbform = response.data;
        this.openZb = true;
        this.title = "修改模版指标管理";
        this.zbform.isSynZb = "1";
      });
    },
    submitMbZbForm() {
      this.$refs["zbform"].validate(valid => {
        if (valid) {
          if (this.zbform.zbId != null) {
            updateMbZbmanage(this.zbform).then(response => {
              this.$modal.msgSuccess("模版指标修改成功");
              this.openZb = false;
              this.getList();
            });
          } else {
            addMbZbmanage(this.zbform).then(response => {
              this.$modal.msgSuccess("模版指标新增成功");
              this.openZb = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.mbGoalId != null) {
            updateZrsMbManageGoal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZrsMbManageGoal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    selectChange(e,code){
       let param = {
          mbId :this.mbId,
          zbId :code,
          zrsZbCheckdate:e
       }
       updateZrsMbGlxZb(param).then(response => {
          this.$modal.msgSuccess("考核周期自动保存成功！！");
        });
    },
    selectChangeShDept(e,code){
       let param = {
          mbId :this.mbId,
          zbId :code,
          zrszbShDept:e
       }
       updateZrsMbGlxZb(param).then(response => {
          this.$modal.msgSuccess("考核部门自动保存成功！！");
        });
    },
  }
};
</script>

<style>
  .demo-shadow {
      height: 100px;
      width: 50%;
      border: 1px solid #eee;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
  }
  .topDiv{
    padding-top: 40px;
    width: 100%;
    text-align:center;
    font-size: 22px;
  }
  .talbeDiv{
    padding-left: 40px;
    padding-top: 30px;
  }
  .talbeClass{
    border: 1px solid rgba(0,0,0,1);
    border-collapse: collapse;
    border-spacing: 0;
    max-width: 99%;
  }
  .table-bordered{
      /**  border: 1px solid rgba(0,0,0,1);**/
  }
  .table-bordered > thead > tr > th,
  .table-bordered > tbody > tr > th,
  .table-bordered > tfoot > tr > th,
  .table-bordered > thead > tr > td,
  .table-bordered > tbody > tr > td,
  .table-bordered > tfoot > tr > td{
      border: 1px solid rgba(0,0,0,1);
      text-align: center;
      font-weight: bold;
      padding:3px;
  }
  .table-striped > tr:nth-of-type(odd) {
      background-color:#c7c8c8;
  }
  .table_title_center{
      text-align: center;
  }
  .table_title_left{
      text-align: left;
  }
  .table_title_bold{
      font-weight: bold;
  }
  .el-transfer-panel{
    width: 330px;
  }
  .el-transfer-panel__body{
    height: 400px;
  }
  .el-transfer-panel__list{
    height: 400px;
  }
  .el-transfer-panel__list.is-filterable{
    height: 360px;
    padding-top: 0;
  }
</style>
